package com.ape.service.impl;

import com.ape.dao.IStudentDao;
import com.ape.pojo.Student;
import com.ape.pojo.query.StudentQuery;
import com.ape.service.IStudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements IStudentService {
    @Autowired
    private IStudentDao iStudentDao;

    @Override
    public List<Student> listStudent() {
        return iStudentDao.listStudent();
    }

    @Override
    public PageInfo<Student> listStudentByName(StudentQuery studentQuery) {
        PageHelper.startPage(studentQuery.getPageNum(),studentQuery.getPageSize());
        return new PageInfo<Student>(iStudentDao.listStudentByName(studentQuery));
    }

    @Override
    public boolean deleteStudentById(Integer Sid) {
        int i = iStudentDao.deleteStudentById(Sid);
        if (i > 0){
            return true;//删除成功
        }else {
            return false;//删除失败
        }
    }

    @Override
    public Student queryStudentById(Integer sid) {
        return iStudentDao.queryStudentById(sid);
    }

    @Override
    public boolean updateStudent(Student student) {
        int i = iStudentDao.updateStudent(student);
        if (i>0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<Student> queryStudentByName(Student student) {
        return iStudentDao.queryStudentByName(student);
    }

    @Override
    public boolean addStudent(Student student) {
        return iStudentDao.addStudent(student) > 0 ? true : false;
    }
}
